package com.wxy.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wxy.entity.Saledata;
import com.wxy.entity.Salemonthdata;
import com.wxy.mapper.SalemonthdataMapper;
import com.wxy.selectUser.SelectUser;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import javax.servlet.http.HttpServletRequest;
import java.sql.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author wxy
 * @since 2022-01-12
 */
@RestController
@RequestMapping("/saleMonthData")
public class SalemonthdataController {

    @Autowired
    private SalemonthdataMapper salemonthdataMapper;

    //按月账单查询
    @GetMapping("/getMonthData/{page}")
    public IPage getMonthData(
            HttpServletRequest request,
            @PathVariable("page") Integer pageNum
    ){
        //取出page
        QueryWrapper qw =  SelectUser.saleDayDataSelectUser(request.getHeader("userId"));
        qw.orderByDesc("time");
        IPage page = new Page(pageNum,10);
        return salemonthdataMapper.selectPage(page,qw);
    }


    //按月查询
    @GetMapping("/getMonthDataByTime/{time}")
    public List getDayDataByTime(
            HttpServletRequest request,
            @PathVariable("time") String time
    ){

        //取出page
        QueryWrapper qw =  SelectUser.saleDataSelectUser(request.getHeader("userId"));
        qw.eq("time",time);
        return salemonthdataMapper.selectList(qw);
    }
}

